<?php

namespace vola\model\connection;

use vola\model\Connection;


class We7Connection extends Connection
{
    private $beginning = false;
    public $lastsql;

    public function query($statement, array $data = array())
    {
        $this->convertSql($statement, $data);
        if ($this->closeSql($statement, $data)) {
            return 0;
        }
        return pdo_query($statement, $data);
    }

    public function fetch($statement, array $data = array())
    {
        $this->convertSql($statement, $data);
        if ($this->closeSql($statement, $data)) {
            return 0;
        }
        return pdo_fetch($statement, $data);
    }

    public function fetchall($statement, array $data = array())
    {
        $this->convertSql($statement, $data);
        if ($this->closeSql($statement, $data)) {
            return 0;
        }
        return pdo_fetchall($statement, $data);
    }

    public function fetchcolumn($statement, array $data = array())
    {
        $this->convertSql($statement, $data);
        if ($this->closeSql($statement, $data)) {
            return 0;
        }
        return pdo_fetchcolumn($statement, $data);
    }

    /**
     * 获取执行中的错误
     * @return array 返回错误信息
     */
    public function rollback()
    {
        if ($this->beginning) {
            pdo_rollback();
        }
    }

    public function begin()
    {
        $this->beginning = true;
        pdo_begin();
    }

    public function commit()
    {
        try {
            pdo_commit();
        } catch (\Exception $e) {
            echo $e->getMessage();
        } // TODO: Change the autogenerated stub
    }

    public function lastid() {
        return pdo_insertid();
    }

    public function tablename($table) {
        return tablename($table);
    }

    public function getLastsql(){
        $error = pdo_debug(false);
        $error = end($error);
        return array($this->lastsql[0],$error);
    }
}
